<?php
declare (strict_types = 1);

namespace app\model;

class Order extends BaseModel
{
    protected $name = 'order';
    
    // 关联用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }
    
    // 关联配送员
    public function delivery()
    {
        return $this->belongsTo(Delivery::class);
    }
    
    // 关联支付记录
    public function payment()
    {
        return $this->hasOne(Payment::class);
    }
    
    // 生成订单号
    public static function generateOrderNo()
    {
        return date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    }
} 